<?php

class UsuariosController extends AppController {

    var $name = 'Usuarios';
    var $helpers = array('Ajax', 'Javascript', 'Time');

    function index() {
        $this->Usuario->recursive = 0;
        $this->set('usuarios', $this->paginate());
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid usuario', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('usuario', $this->Usuario->read(null, $id));
    }

    function add() {
        if (!empty($this->data)) {
            $this->Usuario->create();
            if ($this->Usuario->save($this->data)) {
                $this->Session->setFlash(__('The usuario has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The usuario could not be saved. Please, try again.', true));
            }
        }
        $groups = $this->Usuario->Group->find('list');
        $this->set(compact('groups'));
    }

    function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid usuario', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Usuario->save($this->data)) {
                $this->Session->setFlash(__('The usuario has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The usuario could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Usuario->read(null, $id);
        }
        $groups = $this->Usuario->Group->find('list');
        $this->set(compact('groups'));
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for usuario', true));
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Usuario->delete($id)) {
            $this->Session->setFlash(__('Usuario deleted', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Usuario was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }

    function admin_index() {
        $this->Usuario->recursive = 0;
        $this->set('usuarios', $this->paginate());
    }

    function admin_view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid usuario', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('usuario', $this->Usuario->read(null, $id));
    }

    function admin_add() {
        if (!empty($this->data)) {
            $this->Usuario->create();
            if ($this->Usuario->save($this->data)) {
                $this->Session->setFlash(__('The usuario has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The usuario could not be saved. Please, try again.', true));
            }
        }
        $groups = $this->Usuario->Group->find('list');
        $this->set(compact('groups'));
    }

    function admin_edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid usuario', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Usuario->save($this->data)) {
                $this->Session->setFlash(__('The usuario has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The usuario could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Usuario->read(null, $id);
        }
        $groups = $this->Usuario->Group->find('list');
        $this->set(compact('groups'));
    }

    function admin_delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for usuario', true));
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Usuario->delete($id)) {
            $this->Session->setFlash(__('Usuario deleted', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Usuario was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }

 

}

?>